.TH std::counted_iterator::base 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::counted_iterator::base \- std::counted_iterator::base

.SH Synopsis
   constexpr const I& base() const& noexcept; \fB(1)\fP \fI(since C++20)\fP
   constexpr I base() &&;                     \fB(2)\fP \fI(since C++20)\fP

   Returns the underlying base iterator.

   1) Returns a reference to the underlying iterator.
   2) Move constructs the return value from the underlying iterator.

.SH Parameters

   \fI(none)\fP

.SH Return value

   1) A reference to the underlying iterator.
   2) An iterator move constructed from the underlying iterator.

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <iterator>
 #include <type_traits>
 #include <vector>

 int main()
 {
     std::vector<int> v{0, 1, 2, 3, 4};

     std::reverse_iterator<std::vector<int>::iterator> reverse{v.rbegin()};

     std::counted_iterator counted{reverse, 3};

     static_assert(std::is_same<
         decltype(counted.base()),
         std::reverse_iterator<std::vector<int>::iterator> const&
     >{});

     std::cout << "Print with reverse_iterator: ";
     for (auto r = counted.base(); r != v.rend(); ++r)
         std::cout << *r << ' ';
     std::cout << '\\n';

     std::cout << "Print with counted_iterator: ";
     for (; counted != std::default_sentinel; ++counted)
         std::cout << counted[0] << ' ';
     std::cout << '\\n';
 }

.SH Output:

 Print with reverse_iterator: 4 3 2 1 0
 Print with counted_iterator: 4 3 2

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to            Behavior as published              Correct behavior
   LWG 3391 C++20      the const version of base returns a copy of  returns a reference
                       the underlying iterator
   LWG 3593 C++20      the const version of base returns a          made noexcept
                       reference but might not be noexcept

.SH See also

   operator*  accesses the pointed-to element
   operator-> \fI(public member function)\fP
   (C++20)
   count      returns the distance to the end
   (C++20)    \fI(public member function)\fP
